#!/usr/bin/perl
use strict;
#use XML::Simple;
#use Data::Dumper;
#use Socket;
#
#my $config = XMLin("crawl_page.xml");
#print Dumper($config);
#print scalar keys %$config, "\n";
#
#my $sock = undef;
#print $sock, "\n";
#socket($sock, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
#print $sock, "\n";
#close $sock;
#$sock = undef;
#socket($sock, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
#print $sock, "\n";
#
#&conn(\$sock);
#
#sub conn {
#	my $sock = shift;
#	
#	print $$sock, "\n";
#	socket($$sock, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
#	print $$sock, "\n";
#}
#
#my %tt;
#foreach (keys %tt) {
#	print "haha\n";
#}
##my $abc = $tt{'localhost'}{80};
##push @$abc, "123";
#push @{$tt{'localhost'}{80}}, '123';
#my $bc = $tt{'localhost'}{80};
#print scalar @$bc, "\n";

use IO::Socket::INET;

my $http_req = "GET / HTTP/1.1\r\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-silverlight, */*\r\nAccept-Language: zh-cn\r\nUA-CPU: x86\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; CNCDialer; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) )\r\nHost: www.google.cn\r\nConnection: Keep-Alive\r\n\r\n";
my $sock = IO::Socket::INET->new(PeerAddr => "www.google.cn", PeerPort => 'http(80)', Proto => 'tcp') or die "$@\n";
print $sock $http_req;
my $buf;
my $len = $sock->sysread($buf, 8192);
open FILE, ">/tmp/http_out";
binmode FILE;
syswrite FILE, $buf, $len;
close FILE;
#my $internet_addr = inet_aton("202.204.96.207");
#my $internet_addr = inet_aton("127.0.0.1");
#my $paddr = sockaddr_in(22, $internet_addr);
#$! = 0;
#my $ret = $sock->connect($paddr);
#if ($ret) {
#	print $ret, "\n";
#}
#if ($! == 0) {
#	print "$!\n";
#}
#print $sock->connected, "\n";
#print $sock "GET /\r\n";
#print <$sock>;
